<?php

namespace App\Listeners;

use App\Models\Referral;
use Filament\Events\Auth\Registered;
use App\Models\User;

class ReferralRecordUpdate
{

    public function __construct()
    {
        //
    }
    /**
     * Handle the event.
     */
    public function handle(Registered $event): void
    {
        $user_id = $event->getUser()->id;
        $referred_by = $event->getUser()->referred_by;
        if ($referred_by) {
            $referral = new Referral();
            $referral->user_id = $user_id;
            $referral->referred_by = $referred_by;
            $referral->save();
        }
    }
}
